using System;
using System.Collections.Generic;
using System.Text;

namespace CodePlex.OpenSearch
{


    /// <summary>
    /// Response to a search request.
    /// </summary>
    public class SearchResponse
    {

        private readonly string _searchTerms;
        private readonly int _startPage;

        private readonly int _firstPage;
        private readonly int _previousPage;
        private readonly int _nextPage;
        private readonly int _lastPage;


        private readonly DateTime _updated;
        private readonly int _totalResults;
        private readonly int _startIndex;
        private readonly int _itemsPerPage;

        
        private readonly string _searchTitle;
        private readonly string _searchLink;
        private readonly string _searchDescription;
        private readonly string _searchID;
        private readonly string _searchAuthorName;

        private readonly IEnumerable<SearchResult> _results;


        /// <summary>
        /// Constructs a new <see cref="SearchResponse"/>.
        /// </summary>
        public SearchResponse(string searchTerms, int startPage,

            int firstPage, int previousPage, int nextPage, int lastPage, 
            
            string searchTitle, string searchLink, string searchDescription,
            string searchID, string searchAuthorName,
            DateTime updated, int totalResults, int startIndex, int itemsPerPage,
            IEnumerable<SearchResult> results)
        {
            _searchTerms = searchTerms;
            _startPage = startPage;

            _firstPage = firstPage;
            _previousPage = previousPage;
            _nextPage = nextPage;
            _lastPage = lastPage;

            _searchTitle = searchTitle;
            _searchLink = searchLink;
            _searchDescription = searchDescription;
            _searchID = searchID;
            _searchAuthorName = searchAuthorName;

            _updated = updated;
            _totalResults = totalResults;
            _startIndex = startIndex;
            _itemsPerPage = itemsPerPage;

            _results = results;

        }

        /// <summary>
        /// Search results for this page listed as <see cref="SearchResult"/> items.
        /// </summary>
        public IEnumerable<SearchResult> Results
        {
            get
            {
                return _results;
            }
        }


        /// <summary>
        /// Original search string.
        /// </summary>
        public string SearchTerms
        {
            get
            {
                return _searchTerms;
            }

        }

        /// <summary>
        /// Current page in the search results.
        /// </summary>
        public int StartPage
        {
            get
            {
                return _startPage;
            }
        }

        /// <summary>
        /// First page in the search results.
        /// </summary>
        public int FirstPage
        {
            get
            {
                return _firstPage;
            }
        }

        /// <summary>
        /// Previous page in the search results.
        /// </summary>
        public int PreviousPage
        {
            get
            {
                return _previousPage;
            }
        }

        /// <summary>
        /// Next page in the search results.
        /// </summary>
        public int NextPage
        {
            get
            {
                return _nextPage;
            }
        }

        /// <summary>
        /// Last page in the search results.
        /// </summary>
        public int LastPage
        {
            get
            {
                return _lastPage;
            }
        }

        /// <summary>
        /// Short summary of the search performed.
        /// </summary>
        public string SearchTitle
        {
            get
            {
                return _searchTitle;
            }
        }

        /// <summary>
        /// Canonical link back to this search.
        /// </summary>
        public string SearchLink
        {
            get
            {
                return _searchLink;
            }
        }

        /// <summary>
        /// Longer description of the search performed.
        /// </summary>
        public string SearchDescription
        {
            get
            {
                return _searchDescription;
            }
        }

        /// <summary>
        /// Unique ID for the search performed.  Many times it can simply be the <see cref="SearchLink"/>.
        /// </summary>
        public string SearchID
        {
            get
            {
                return _searchID;
            }
        }

        /// <summary>
        /// Author of the search service.
        /// </summary>
        public string SearchAuthorName
        {
            get
            {
                return _searchAuthorName;
            }
        }

        /// <summary>
        /// Last time the results of this search changed.
        /// </summary>
        public DateTime Updated
        {
            get
            {
                return _updated;
            }
        }

        /// <summary>
        /// Total number of results for the search performed.
        /// </summary>
        public int TotalResults
        {
            get
            {
                return _totalResults;
            }
        }

        /// <summary>
        /// Index of the first search result in the current set of search results. 
        /// </summary>
        public int StartIndex
        {
            get
            {
                return _startIndex;
            }
        }


        /// <summary>
        /// The number of search results returned per page.
        /// </summary>
        public int ItemsPerPage
        {
            get
            {
                return _itemsPerPage;
            }
        }
    }
}
